package com.yn.xgame.logic.util;

import java.math.BigInteger;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;

public class CheckUtils {

	public static final String REGEX_USERNAME = "\\w{6,16}";
	public static final String REGEX_NICKNAME = "^[\\w\\u4E00-\\u9FA5\\uF900-\\uFA2D]{6,16}$";
	public static final String REGEX_PASSWORD = "[\\s\\S]{6,20}";
	public static final String REGEX_MOBILE_PHONE = "^1[3|4|5|8][0-9]\\d{8}$";
	public static final String REGEX_INT_ID="[1-9]\\d*";

	public static boolean checkUserName(String username) {
		if(StringUtils.isNotBlank(username)){
			return Pattern.matches(REGEX_USERNAME, username);
		}
		return false;
	}
	
	public static boolean checkNickName(String nickname){
		if(StringUtils.isNotBlank(nickname)){
			return Pattern.matches(REGEX_NICKNAME, nickname);
		}
		return false;
	}
	
	public static boolean checkPassword(String password){
		if(StringUtils.isNotBlank(password)){
			return Pattern.matches(REGEX_PASSWORD, password);
		}
		return false;
	}
	
	public static boolean checkMobilePhoneNo(String phoneNo){
		if(StringUtils.isNotBlank(phoneNo)){
			return Pattern.matches(REGEX_MOBILE_PHONE, phoneNo);
		}
		return false;
	}
	
	public static boolean checkIntId(String id){
		if(StringUtils.isNotBlank(id)&&Pattern.matches(REGEX_INT_ID, id)){
			BigInteger bigInt=new BigInteger(id);
			if(bigInt.compareTo(BigInteger.valueOf(Integer.MAX_VALUE))!=1){
				return true;
			}
		}
		return false;
	}
}
